//
//  CloudBL.m
//  APIDemo
//
//  Created by 宣佚 on 15/6/1.
//  Copyright (c) 2015年 Andon Health Co,.Ltd. All rights reserved.
//

#import "CloudBL.h"
#import "CloudDao.h"

@implementation CloudBL

/**
 *  申请手机注册验证码，对应API 1
 *
 *  @param Phone   申请手机
 *  @param success 成功返回
 *  @param failure 失败返回
 */
+(void)GetRegisterVerityCode_Phone:(NSString *)Phone
                           success:(void (^)(void))success
                           failure:(void (^)(NSString *errorMessage))failure
{
    PostGetRegisterVerityCodeModel *model = [[PostGetRegisterVerityCodeModel alloc] init];
    model.phone = Phone;
    NSDictionary *topInfo = [model dictionaryRepresentation];
    
    [CloudDao GetRegisterVerityCode:topInfo
                            success:^(id returnValue) {
                                success();
                            }
                            failure:^(NSString *errorMessage) {
                                failure(errorMessage);
                            }
                          exception:^(NSString *errorMessage) {
                              failure(@"网络请求异常");
                          }
     ];
}

/**
 *  验证手机注册验证码，对应API 2
 *
 *  @param Phone   申请手机
 *  @param Code    申请手机验证码
 *  @param success 成功返回 BOOL
 *  @param failure 失败返回
 */
+(void)VerityRegisterCode_Phone:(NSString *)Phone
                           Code:(NSString *)Code
                        success:(void (^)(BOOL VerityisSuccess))success
                        failure:(void (^)(NSString *errorMessage))failure
{
    PostVerityRegisterCodeModel *model = [[PostVerityRegisterCodeModel alloc] init];
    model.phone = Phone;
    model.code = Code;
    NSDictionary *topInfo = [model dictionaryRepresentation];
    
    [CloudDao VerityRegisterCode:topInfo
                         success:^(id returnValue) {
                             if ([returnValue intValue] == 1)
                             {
                                 success(YES);
                             }
                             else if ([returnValue intValue] == 0)
                             {
                                 success(NO);
                             }
                         }
                         failure:^(NSString *errorMessage) {
                             failure(errorMessage);
                         }
                       exception:^(NSString *errorMessage) {
                           failure(@"网络请求异常");
                       }];
}

/**
 *  手机账号注册，对应API 3
 *
 *  @param Phone     申请手机
 *  @param Code      申请手机验证码
 *  @param Password  申请手机密码
 *  @param success   成功返回
 *  @param failure   失败返回
 */
+(void)RegisterUser_Phone:(NSString *)Phone
                     Code:(NSString *)Code
                 Password:(NSString *)Password
                  success:(void (^)(NSString *iDentity, Token *token))success
                  failure:(void (^)(NSString *errorMessage))failure
{
    PostRegisterUserModel *model = [[PostRegisterUserModel alloc] init];
    model.phone = Phone;
    model.code = Code;
    model.password = Password;
    NSDictionary *topInfo = [model dictionaryRepresentation];
    
    [CloudDao RegisterUser:topInfo
                   success:^(id returnValue) {
                       RegisterUserModel *userModel = [RegisterUserModel modelObjectWithDictionary:returnValue];
                       success(userModel.hGUID,userModel.token);
                   }
                   failure:^(NSString *errorMessage) {
                       failure(errorMessage);
                   }
                 exception:^(NSString *errorMessage) {
                     failure(@"网络请求异常");
                 }];
}

@end
